package org.jetlinks.community.device.entity;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.hswebframework.ezorm.rdb.mapping.annotation.ColumnType;
import org.hswebframework.ezorm.rdb.mapping.annotation.Comment;
import org.hswebframework.ezorm.rdb.mapping.annotation.DefaultValue;
import org.hswebframework.ezorm.rdb.mapping.annotation.JsonCodec;
import org.hswebframework.web.api.crud.entity.Entity;
import org.hswebframework.web.crud.annotation.EnableEntityEvent;
import org.hswebframework.web.validator.CreateGroup;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.sql.JDBCType;
import java.util.Map;
import java.util.Set;

/**
 * 区域资产实体类
 *
 * @author wangzheng
 * @since 1.0
 */
@Getter
@Setter
@Table(name = "m_dimension_asset", indexes = {
    @Index(name = "idx_dimas_asset_id", columnList = "asset_id"),
    @Index(name = "idx_dimas_asset_type", columnList = "asset_type"),
    @Index(name = "idx_dimas_asset_target", columnList = "asset_target")
})
@Comment("资产维度关联表")
@EnableEntityEvent
public class AssetsEntity implements Entity {
    @Id
    @Column(length = 32)
    @GeneratedValue(generator = "md5")
    @Schema(description = "ID")
    private String id;

    @Column(name = "asset_id",length = 32,nullable = false,updatable = false)
    @Comment("资产id")
    @Schema(description = "资产id")
    private @NotBlank( message = "资产id不能为空",groups = {CreateGroup.class}
    )  String assetId;


    @Column(name = "asset_type",length = 32,nullable = false,updatable = false)
    @Comment("资产类型")
    @Schema(description = "资产类型")
    private @NotBlank( message = "资产不能为空",groups = {CreateGroup.class}
    )String assetType;

    @Column(name = "asset_type_name", length = 64)
    @Comment("资产类型名称")
    @Schema(description = "资产类型名称")
    private String assetTypeName;

    @Column(name = "asset_target",length = 32,updatable = false)
    @Comment("资产目标")
    @Schema(description = "资产目标,如: ID")
    private @NotBlank(message = "资产目标不能为空",groups = {CreateGroup.class}
    ) String assetTarget;

    @Column(name = "asset_target_name",length = 64)
    @Comment("资产目标名称")
    @Schema(description = "资产类型,如: 用户名,角色名")
    private String assetTargetName;

    @Column(name = "asset_target_type",length = 64)
    @Schema(description = "资产类型,如: 用户名,角色名")
    private String assetTargetType;

    @Column(name = "state",nullable = false)
    @Comment("状态")
    @Schema(description = "状态,0禁用,1启用")
    @DefaultValue("1")
    private @NotNull(message = "状态不能为空",groups = {CreateGroup.class}
    ) Byte state;


    @Column
    @ColumnType(jdbcType = JDBCType.CLOB)
    @JsonCodec
    @Comment("可操作权限")
    @Schema(description = "授权可对此权限进行的操作")
    private Set<String> permission;

    @Column
    @ColumnType(jdbcType = JDBCType.LONGVARCHAR)
    @JsonCodec
    @Schema(description = "其他配置")
    private Map<String, Object> properties;

    @Column
    @Comment("优先级")
    @Schema(description = "冲突时,合并优先级")
    private Integer priority;

    @Column
    @Comment("是否合并")
    @Schema(description = "冲突时,是否合并")
    private Boolean merge;


}
